//
//  XmlWelcome.m
//  WelcomePavilion
//
//  Created by wangjun on 10-8-17.
//  Copyright 2010 __MyCompanyName__. All rights reserved.
//
#import "XmlWelcome.h"
@implementation XmlWelcome
@synthesize ones;
//开始一个dom树分析
- (void)parserDidStartDocument:(NSXMLParser *)parser {
	NSLog(@"开始分析树结构");
	ones = [NSMutableArray arrayWithCapacity:100];
		
}
//开始节点 内的信息
- (void)parser:(NSXMLParser *)parser 
didStartElement:(NSString *)elementName 
  namespaceURI:(NSString *)namespaceURI 
 qualifiedName:(NSString *)qualifiedName 
	attributes:(NSDictionary *)attributeDict
{
	
	//NSLog(@"开始的节点是:%@",elementName);
	if ([elementName isEqual:@"title"]) {
		Tag=1;
	}else if ([elementName isEqual:@"content"]) {
		Tag=2;
	}
	if ([elementName isEqual:@"item"]) {
		NSString *lang=[attributeDict objectForKey:@"lang"];
		if ([lang isEqual:@"zh"]) {
			inOne=1;
		}
	}
	if (inOne==1&&[elementName isEqual:@"value"]) {
		inOne=0;
		inTwo=1;
	}
	if ([elementName isEqual:@"image"]) {
		NSString *message=[attributeDict objectForKey:@"src"];
		[one setObject:message forKey:@"image"];
	}
}
//结束节点
- (void)parser:(NSXMLParser *)parser 
 didEndElement:(NSString *)elementName 
  namespaceURI:(NSString *)namespaceURI 
 qualifiedName:(NSString *)qName
{
	//NSLog(@"结束节点:%@",elementName);
	if ([elementName isEqual:@"pavilion"]) {
		Tag=0;
		[ones addObject:one];
		[one release];
	}
}
// 结束dom
- (void)parserDidEndDocument:(NSXMLParser *)parser
{
	
	NSLog(@"结束dom树分析");
}

- (void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)string
{
	//NSLog(@"节点的实际值：%@",string);
	if (inTwo==1) {
		inTwo=0;
		if (Tag==1) {
			one=[[NSMutableDictionary alloc] initWithCapacity:10];
			[one setObject:string forKey:@"title"];
		}else if (Tag==2) {
			[one setObject:string
					forKey:@"content"];
		}
	}
}
@end
